Skip to content

feat(backend): implement environment config validation guard#329

Open
armorbreak001 wants to merge 1 commit intoGalactiGuild:mainfrom
armorbreak001:bounty/292-config-validation-guard
Open

feat(backend): implement environment config validation guard#329
armorbreak001 wants to merge 1 commit intoGalactiGuild:mainfrom
armorbreak001:bounty/292-config-validation-guard

Conversation

@armorbreak001
Copy link
Copy Markdown

Fixes #292

Summary

Added Joi-based environment configuration validation to NestJS ConfigModule. The app now fails fast at startup with clear error messages if required environment variables are missing.

Changes

  • backend/src/common/config/config.validation.ts — New Joi validation schema:

    • Required: DATABASE_URL, JWT_SECRET (min 16 chars)
    • Conditional: REDIS_URL (required unless QUEUE_DISABLED=true)
    • Optional with defaults: PORT, NODE_ENV, STORAGE_PROVIDER, etc.
    • Custom error messages: "Missing Configuration: XYZ"
    • Supports storage (local/S3/IPFS), mail (SMTP), and app config
  • backend/src/app.module.ts — Updated ConfigModule.forRoot():

    • Added validationSchema: configValidationSchema
    • abortEarly: false — reports all errors at once
    • Missing vars → clear console error + process.exit(1) (NestJS default behavior)

Prerequisites

cd backend && npm install joi

Verification

# Test 1: Missing required var → crash on startup
unset DATABASE_URL && npm run start
# → Error: "Missing Configuration: DATABASE_URL"

# Test 2: Invalid JWT_SECRET → crash
export JWT_SECRET="short"
npm run start
# → Error: "JWT_SECRET must be at least 16 characters"

# Test 3: All valid → starts normally
export DATABASE_URL="postgresql://..." JWT_SECRET="my-super-secret-key-12345"
npm run start
# → ✅ Server listening on port 3000

- Add Joi validation schema for all required env vars
- Strictly requires: DATABASE_URL, JWT_SECRET, PORT
- Conditionally requires REDIS_URL unless QUEUE_DISABLED is set
- Validates JWT_SECRET minimum length (16 chars)
- Aborts on startup with clear error messages for missing config
- Supports storage, mail, and app configuration options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Implement Environment Config Validation Guard (Joi/Zod)

1 participant